package photorganizer.common.helper;

public class StackTraceHelper {

	public static StackTraceElement getInvokingStackTraceElement(Class<?> invoked) {
		return getInvokingStackTraceElement(invoked.getName());
	}

	public static StackTraceElement getInvokingStackTraceElement(Package invoked) {
		return getInvokingStackTraceElement(invoked.getName());
	}

	private static StackTraceElement getInvokingStackTraceElement(String invoked) {
		StackTraceElement result = null;
		boolean found = false;
		StackTraceElement[] elements = (new Throwable()).getStackTrace();
		for (StackTraceElement element : elements) {
			if (element.getClassName().startsWith(invoked)) {
				found = true;
			}
			else if (found) {
				result = element;
				break;
			}
		}
		return result;
	}

	private StackTraceHelper() {
		assert false;
	}

}
